<!DOCTYPE html>
<html lang="zh-CN">
<head>
    {% load static %}
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}本地图书馆{% endblock %}</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- 自定义CSS -->
    <link rel="stylesheet" href="{% static 'css/custom.css' %}">
    <!-- Font Awesome 图标 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    {% block extra_css %}{% endblock %}
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container">
            <a class="navbar-brand" href="{% url 'index' %}">
                <i class="fas fa-book-open me-2"></i>本地图书馆
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'index' %}"><i class="fas fa-home me-1"></i>首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'books' %}"><i class="fas fa-book me-1"></i>所有书籍</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'authors' %}"><i class="fas fa-user me-1"></i>所有作者</a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    {% if user.is_authenticated %}
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown">
                                <i class="fas fa-user-circle me-1"></i>{{ user.get_username }}
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end">
                                <li><a class="dropdown-item" href="{% url 'my-borrowed' %}"><i class="fas fa-list-alt me-1"></i>我的借阅</a></li>
                                <li><a class="dropdown-item" href="{% url 'personalized_recommendations' %}"><i class="fas fa-star me-1"></i>个性化推荐</a></li>
                                <li><hr class="dropdown-divider"></li>
                                <li><a class="dropdown-item" href="{% url 'logout' %}"><i class="fas fa-sign-out-alt me-1"></i>退出登录</a></li>
                            </ul>
                        </li>
                    {% else %}
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'login' %}"><i class="fas fa-sign-in-alt me-1"></i>登录</a>
                        </li>
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <div class="row">
            <main class="col-md-8">
                {% if messages %}
                    {% for message in messages %}
                        <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                            {{ message }}
                            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                        </div>
                    {% endfor %}
                {% endif %}
                {% block content %}{% endblock %}
            </main>
            <aside class="col-md-4">
                <div class="card mb-4">
                    <div class="card-header bg-primary text-white">
                        <h5 class="mb-0"><i class="fas fa-info-circle me-2"></i>图书馆信息</h5>
                    </div>
                    <div class="card-body">
                        <p>欢迎使用本地图书馆系统。</p>
                        <p>我们共有：
                            <strong>{{ num_books }}</strong> 本书籍<br>
                            <strong>{{ num_instances }}</strong> 个副本<br>
                            <strong>{{ num_instances_available }}</strong> 个可借阅副本<br>
                            <strong>{{ num_authors }}</strong> 位作者
                        </p>
                        {% if user.is_authenticated %}
                            <p>您已访问本页面 <strong>{{ num_visits }}</strong> 次。</p>
                        {% endif %}
                    </div>
                </div>
                <div class="card">
                    <div class="card-header bg-secondary text-white">
                        <h5 class="mb-0"><i class="fas fa-fire me-2"></i>热门书籍</h5>
                    </div>
                    <div class="card-body">
                        <ul class="list-group list-group-flush">
                            {% for book in popular_books|slice:5 %}
                                <li class="list-group-item book-list-item">
                                    <a href="{% url 'book-detail' book.id %}">{{ book.title }}</a>
                                    <span class="badge bg-success float-end">{{ book.borrow_count }} 次借阅</span>
                                </li>
                            {% empty %}
                                <li class="list-group-item">暂无热门书籍数据</li>
                            {% endfor %}
                        </ul>
                    </div>
                </div>
            </aside>
        </div>
    </div>

    <footer class="footer mt-auto">
        <div class="container text-center">
            <p>&copy; {% now "Y" %} 本地图书馆管理系统</p>
            <p class="mb-0">
                <a href="#" class="text-light me-3"><i class="fas fa-question-circle"></i>帮助中心</a>
                <a href="#" class="text-light me-3"><i class="fas fa-file-alt"></i>关于我们</a>
                <a href="#" class="text-light"><i class="fas fa-envelope"></i>联系我们</a>
            </p>
        </div>
    </footer>

    <!-- Bootstrap JS Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    {% block extra_js %}{% endblock %}
</body>
</html>
